package study;

import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;

/**
 * @version 1.0
 * @since:
 * @ClassName:LinkMethodTest
 * @author: Li Jiahui
 * @date: 2021-04-25 15:14
 */
public class LinkMethodTest {
    public static void main(String[] args) {
        //1.准备一个List集合并打印
        List lt1 = new LinkedList();
        System.out.println("c1 =" +lt1);
        //2.向集合中添加元素并打印
        lt1.add(0,"one");
        System.out.println("lt1 = " + lt1);
        //3.向集合的未尾位置添加元素
        lt1.add(1, 3);
        System.out.println("lt1 = " + lt1);
        //4.向集合中的中间位置添加元素
        lt1.add(0,2);
        System.out.println("lt1 = " + lt1);
        System.out.println("----------------------");
        //根据参数指定的下标来获取元素
        Object pos = lt1.get(0);
        System.out.println("pos =" + pos);
        for(int i = 0; i <lt1.size(); i++){
            System.out.println("下标为：" +i +",元素为：" + lt1.get(i));
        }
        System.out.println(lt1.indexOf("one"));
        Object obj = lt1.set(0,1);
        System.out.println("obj = " + obj);
        System.out.println(lt1.get(0));
        System.out.println("----------------------");
        System.out.println(lt1.subList(1,2));
        System.out.println("----------------------");
        for(int i = lt1.size()-1 ; i >= 0 ; i--){
            System.out.println("被删除的元素为：" + lt1.remove(i));
        }
        System.out.println(lt1);

    }
}
